package com.xinxin.datastructure.queue.impl;

import com.xinxin.datastructure.linkedlist.LinkedList;
import com.xinxin.datastructure.queue.Queue;

/**
 * @author ：史鑫鑫
 * @date ：Created in 2019/4/24 16:01
 */
public class LinkedListQueue<E> implements Queue<E> {
    LinkedList<E> linkedList;

    public LinkedListQueue() {
        this.linkedList = new LinkedList();
    }

    @Override
    public void enqueue(E e) {
        linkedList.addLast(e);
    }

    @Override
    public E dequeue() {
        return linkedList.removeFirst();
    }

    @Override
    public E getFront() {
        return linkedList.getFirst();
    }

    @Override
    public int getSize() {
        return linkedList.getSize();
    }

    @Override
    public boolean isEmpty() {
        return linkedList.isEmpty();
    }

    @Override
    public String toString() {
        return String.format("Queue: size=%d\nhead %s tail", getSize(), linkedList);
    }
}
